import paho.mqtt.client as mqtt

def on_connect(client, userdata, flags, rc):
    client.subscribe("home/sensor")  # 订阅敏感主题

client = mqtt.Client()
client.on_connect = on_connect
client.connect("localhost", 1883, 60)  # 假设MQTT服务器在本地
client.loop_forever()